home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CDTV / cdtvtools-11 / CD-DA / repeattrack.c
Encoding:
C/C++ Source or Header  |  1991-06-12  |  3.8 KB  |  96 lines

  1. /***********************************************************************
  2. ***
  3. *** "RepeatTrack"  Repeats a CD audio track.
  4. *** v1.1 Adam Keith Levin  Commodore Applications and Technical Support
  5. *** Based upon Carl's CDTV CD-Audio Player 1.0
  6. ***
  7. *** Free to Distribute amoung CDTV developers.
  8. ***
  9. *** Pass it a track number from the CLI; it will repeat that track.
  10. *** If no track is given, it repeats DEFAULT_TRACK (#defined below).
  11. *** If you press CTRL-C it will stop repeating once the track finishes.
  12. ***
  13. ***********************************************************************/
  14.  
  15. #include <exec/types.h>
  16. #include <exec/io.h>
  17. #include <libraries/dos.h>
  18. #include <stdio.h>
  19. #include "cdtv.h"
  20.  
  21. extern struct   IOStdReq *CreateStdIO();
  22. extern struct   MsgPort  *CreatePort();
  23. struct IOStdReq *IORequest = NULL;
  24. struct MsgPort  *IOPort = NULL;
  25.  
  26. #define TOC_entries 100
  27. struct CDTOC    Toc[TOC_entries];
  28.  
  29. #define CTRL_C     (SetSignal(0L, 0L) & SIGBREAKF_CTRL_C)
  30.  
  31. #define DEFAULT_TRACK 1
  32.  
  33.  
  34. main(int argc, char *argv[])
  35. {
  36. int track = DEFAULT_TRACK, last;
  37.  
  38.         /* Parse argument (if any). */
  39.         if (argc > 1)
  40.         {
  41.                 track = atoi(argv[1]);
  42.                 if (!track)
  43.                         track = DEFAULT_TRACK;
  44.         }
  45.  
  46.         IOPort = CreatePort(0,0);
  47.         if (NULL == IOPort)
  48.                 printf("Unable to create port.\n");
  49.         else
  50.         {
  51.                 IORequest = CreateStdIO(IOPort);
  52.                 if (NULL == IORequest)
  53.                         printf("Unable to create I/O request.\n");
  54.                 else
  55.                 {
  56.                         if (OpenDevice(CD_NAME,0,IORequest,0))
  57.                                 printf("Unable to open the CDTV device.\n");
  58.                         else
  59.                         {
  60.                                 /* Obtain TOC and examine number of tracks on disc. */
  61.                                 IORequest->io_Command = CD_TOCMSF;
  62.                                 IORequest->io_Offset = 0;
  63.                                 IORequest->io_Length = TOC_entries;
  64.                                 IORequest->io_Data   = &Toc[0];
  65.                                 if (DoIO(IORequest))
  66.                                         printf("Unable to examine disc's Table of Contents.\n");
  67.                                 else
  68.                                 {
  69.                                         /* Insure that disc has enough tracks. */
  70.                                         last = Toc[0].LastTrack;
  71.                                         if (track > last)
  72.                                                 printf("Not that many tracks (last track is %d).\n", last);
  73.                                         else
  74.                                         {
  75.                                                 /* Keep playing the track until CTRL-C is sensed.
  76.                                                    (To abort play during a track use CD_STOPPLAY.)
  77.                                                 */
  78.                                                 while (! CTRL_C)
  79.                                                 {
  80.                                                         IORequest->io_Command = CD_PLAYTRACK;
  81.                                                         IORequest->io_Offset = track;
  82.                                                         IORequest->io_Length = 0;
  83.                                                         IORequest->io_Data   = NULL;
  84.                                                         if (DoIO(IORequest))
  85.                                                                 printf("Unable to play track %d.\n", track);
  86.                                                 }
  87.                                         }
  88.                                 }
  89.                         CloseDevice(IORequest);
  90.                         }
  91.                 DeleteStdIO(IORequest);
  92.                 }
  93.         DeletePort(IOPort);
  94.         }
  95. }
  96.